/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2022-11-24 11:40:36
 * @LastEditors: TT
 * @LastEditTime: 2023-03-08 22:24:17
 */

import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:ttcomment/ttcomment.dart';
import 'hzy_normal_state_widget.dart';
import 'hzy_normal_utils.dart';

abstract class NormalListState<T extends StatefulWidget> extends NormalState<T>
    with AbstracRefreshWidget, AbstractNetWork, AbstracRefreshMehod {
  /// 属性
  ///
  ///

  EasyRefreshController? refreshController;
  @override
  bool get safeAreabottm => false;
  @override
  void initDefaultState() {
    refreshController = EasyRefreshController();
    super.initDefaultState();
  }

  @override
  void initDefaultDispose() {
    refreshController?.dispose();
    super.initDefaultDispose();
  }

  @override
  Widget createCommBaseWidget(
    BuildContext context,
    PageState pageState,
  ) {
    return createColumWidget(context);
  }

  @override
  Widget createBody(BuildContext context) {
    return createRefreshWidget(context);
  }

  @override
  Widget createRefreshWidget(BuildContext context) {
    return EasyRefresh(
      controller: refreshController,
      onRefresh: () async {
        configRefresh();
      },
      onLoad: () async {
        configLoading();
      },
      header: createHeader(),
      footer: createFooter(),
      child: createListView(context),
    );
  }

  /// 自定义刷新控件 header
  Header? createHeader() {
    return null;
  }

  /// 自定义刷新控件 footer
  Footer? createFooter() {
    return null;
  }

  // 下啦刷新触发事件
  @override
  void configRefresh() {
    page = 1;
    getnetworkdata(type: 1, info: configNetWorkParmas());
  }

  // 上啦加载更多触发事件
  @override
  void configLoading() {
    page++;
    getnetworkdata(type: 2, info: configNetWorkParmas());
  }

  /// 配置网络请求参数
  @override
  Map<String, dynamic>? configNetWorkParmas() {
    return {};
  }

  /// 配置网络请求
 @override
  void getnetworkdata({int? type, Map<String, dynamic>? info}) async {}

  /// 结束刷新
  @override
  void endRefresh(int type, PageState state) {
    HzyNormalUtils.configEndRefresh(
      type: type,
      state: state,
      refreshController: refreshController,
    );
    configsetState(() {});
  }
}
